package work.pcdd.validator.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import work.pcdd.validator.common.ValidateGroup;
import work.pcdd.validator.entity.BatchDeleteRequest;
import work.pcdd.validator.entity.User;

import javax.validation.Valid;
import javax.validation.constraints.Max;
import javax.validation.constraints.NotBlank;

/**
 * @author 1907263405@qq.com
 * @date 2021/4/24 20:39
 */
@Slf4j
@RestController
@Validated
public class TestController {

    @PostMapping("/batch-delete")
    public void batchDelete(@RequestBody @Valid BatchDeleteRequest batchDeleteRequest){
        log.info("batch-delete");
    }

    @PostMapping("test3")
    public User test3(@RequestBody @Validated({ ValidateGroup.FirstGroup.class }) User u) {
        System.out.println(u);
        return u;
    }

    @PostMapping("test4")
    public User test4(@Validated User u) {
        System.out.println(u);
        return u;
    }

    @PostMapping("test41")
    public User test41(@RequestBody @Validated User user) {
        System.out.println(user);
        return user;
    }

    @GetMapping("/test5/{userId}")
    public int test5(@PathVariable(value = "userId") @Max(value = 10) int userId){
        return userId;
    }

    @GetMapping("/test6")
    public String test6(@RequestParam("username") @NotBlank(message = "用户名不能为空") String username,
                        @RequestParam("sex") @NotBlank(message = "性别不能为空") String sex){
        return username + sex;
    }

}




